package InheritanceAndPolymorphism.demo05;

public class CheckAccount extends Account{
    private double overdraft;

    public CheckAccount(int id, double balance, double annualInterestRate, double overdraft) {
        super(id, balance, annualInterestRate);
        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(double amount) {
        if (amount <= balance) {
            balance -= amount;
        } else {
            double needOverdraft = amount - balance;
            if (needOverdraft <= overdraft) {
                overdraft -= needOverdraft;
                balance = 0;
            } else {
                System.out.println("超过可透支额的限额。");
            }
        }
    }

    public double getOverdraft() {
        return overdraft;
    }
}
